/**
 * 项目示例-表单验证规则
 * Date 2023-5-25 09:33:56
 */

import  { FormRules } from 'element-plus'
import { reactive } from 'vue'

var checkPhone = (rule:any, value:any, callback:any) => {
  if (!value) {
    return callback(new Error("手机号不能为空"));
  } else {
    const reg = /^1[3-9][0-9]\d{8}$/;
    // 这里定义的reg变量没有加引号，所以是一种特殊的数据类型，即正则，可以直接用test()方法
    if (reg.test(value)) {
      callback();
    } else {
      // 具体错误信息没有提示
      return callback(new Error("请输入正确的手机号"));
    }
  }
}

export const rules = reactive<FormRules>({
  earlyName: [{
    required: true,
    message: '请输入隐患名称',
    trigger: 'blur'
  },
    { max: 10, message: "隐患名称不超过10个字符", trigger: "blur" }],
  earlyId: [{
    required: true,
    message: '请选择隐患分类',
    trigger: 'change'
  }],
  earlyLevel: [{
    required: true,
    message: '请选择隐患等级',
    trigger: 'change'
  }],
  discoveryTime: [{
    required: true,
    message: '请选择发现时间',
    trigger: 'blur'
  }],
  problemSources: [{
    required: true,
    message: '请选择问题来源',
    trigger: 'change'
  }],
  responsibleUnit: [{
    required: true,
    message: '请选择责任单位',
    trigger: 'change'
  }],
  phone: [
    {
    required: true,
    message: '请输入手机号',
    trigger: 'blur'
  },
    { min: 11, message: "手机号不足11位", trigger: "blur" },
    { validator: checkPhone, trigger: "blur" }
  ],
  person: [
    { max: 10, message: "责任人不超过10个字符", trigger: "blur" }
  ],
  earlyContent: [
    { max: 200, message: "隐患内容不超过200个字符", trigger: "blur" }
  ],
  requirement: [
    { max: 200, message: "整改要求不超过200个字符", trigger: "blur" }
  ],
  pendingReason: [
    // {
    //   required: true,
    //   message: '请输入挂起原因',
    //   trigger: 'blur'
    // },
    { max: 200, message: "挂起原因不超过200个字符", trigger: "blur" }
  ],
  comments: [
    { max: 200, message: "审批意见不超过200个字符", trigger: "blur" }
  ]
})
